package xyz.feiwo.singleton;

/**
 * Created by fei wo at 2021/4/21.
 *
 * @author fei wo <a mailto:feiwodev@foxmail.com>feiwodev@foxmail.com</a>
 * @since 1.0
 *
 * 静态内部类单例模式
 * JVM保证线程安全
 * 加载外部类时，不会加载内部类，这样可以实现懒加载
 */
public class StaticInternalClassSingleton {

    private static class Holder {
        private static StaticInternalClassSingleton INSTANCE = new StaticInternalClassSingleton();
    }

    private StaticInternalClassSingleton(){}

    public static StaticInternalClassSingleton getInstance() {
        return Holder.INSTANCE;
    }

    public static void main(String[] args) {
        StaticInternalClassSingleton singleton01 = StaticInternalClassSingleton.getInstance();
        StaticInternalClassSingleton singleton02 = StaticInternalClassSingleton.getInstance();
        System.out.println(singleton01 == singleton02);
    }
}
